using UnityEngine;
using System.Collections;



public class PlayerInput : MonoBehaviour {

	float speed = 6.0f;
	float jumpSpeed = 8.0f;
	float gravity = 20.0f;
	
	private Vector3 moveDirection = Vector3.zero;
//	private bool grounded = false;

	
	// Use this for initialization
	void Start () {
		
		
	
	}
	
	// Update is called once per frame
	void Update () {
		
		if(transform.position.y > 1.0f)
		{
			moveDirection.y -= gravity * Time.deltaTime;
			if(transform.position.y < 1.0f)
			{
				Vector3 newPos;
				newPos = transform.position;
				newPos.y = 1.0f;
				transform.position = newPos;
			}
		}
		
		if(moveDirection != Vector3.zero)
		{
			transform.position += speed * Time.deltaTime * moveDirection;
		}
		
		if(Input.GetKeyDown(KeyCode.LeftArrow) || Input.GetKeyDown(KeyCode.A))
			moveDirection.x = -1.0f;
		else if (Input.GetKeyDown(KeyCode.RightArrow) || Input.GetKeyDown (KeyCode.D))
			moveDirection.x = 1.0f;
		else if (Input.GetKeyUp (KeyCode.LeftArrow) && Input.GetKeyUp(KeyCode.A) && Input.GetKeyUp(KeyCode.RightArrow) && Input.GetKeyUp (KeyCode.D))
		{	moveDirection.x = 0.0f;
			speed = 0.0f;
		}
		if(Input.GetKeyDown(KeyCode.Space) || Input.GetKeyDown(KeyCode.UpArrow) || Input.GetKeyDown (KeyCode.W))
			moveDirection.y = 5.0f;
		else
			moveDirection.y = 0.0f;
			
		
	}
}
